package com.weather.web.business;

import com.weather.business.domain.SevenEchars;
import com.weather.business.domain.WeatherSevenData;
import com.weather.business.service.IWeatherSevenDataService;
import com.weather.common.annotation.Log;
import com.weather.common.core.controller.BaseController;
import com.weather.common.core.domain.AjaxResult;
import com.weather.common.core.page.TableDataInfo;
import com.weather.common.enums.BusinessType;
import com.weather.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 城市7日天气Controller
 *
 * @author ruoyi
 * @date 2024-03-19
 */
@RestController
@RequestMapping("/business/SevenWeatherData")
public class WeatherSevenDataController extends BaseController
{
    @Autowired
    private IWeatherSevenDataService weatherSevenDataService;

    /**
     * 查询城市7日天气列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WeatherSevenData weatherSevenData)
    {
        startPage();
        List<WeatherSevenData> list = weatherSevenDataService.selectWeatherSevenDataList(weatherSevenData);
        return getDataTable(list);
    }

    /**
     * 查询城市7日天气列表
     */

    @GetMapping("/echars")
    public List<SevenEchars> echarsList(WeatherSevenData weatherSevenData)
    {

        List<SevenEchars> list = weatherSevenDataService.ecahrsList(weatherSevenData);
        return list;
    }

    /**
     * 导出城市7日天气列表
     */

    @Log(title = "城市7日天气", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WeatherSevenData weatherSevenData)
    {
        List<WeatherSevenData> list = weatherSevenDataService.selectWeatherSevenDataList(weatherSevenData);
        ExcelUtil<WeatherSevenData> util = new ExcelUtil<WeatherSevenData>(WeatherSevenData.class);
        util.exportExcel(response, list, "城市7日天气数据");
    }

    /**
     * 获取城市7日天气详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(weatherSevenDataService.selectWeatherSevenDataById(id));
    }

    /**
     * 新增城市7日天气
     */

    @Log(title = "城市7日天气", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WeatherSevenData weatherSevenData)
    {
        return toAjax(weatherSevenDataService.insertWeatherSevenData(weatherSevenData));
    }

    /**
     * 修改城市7日天气
     */

    @Log(title = "城市7日天气", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WeatherSevenData weatherSevenData)
    {
        return toAjax(weatherSevenDataService.updateWeatherSevenData(weatherSevenData));
    }

    /**
     * 删除城市7日天气
     */

    @Log(title = "城市7日天气", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(weatherSevenDataService.deleteWeatherSevenDataByIds(ids));
    }
}
